extends Camera2D

var is_drag

var pressed_mouse_pos = Vector2.ZERO

var pos

var original_camera_pos

func _input(event: InputEvent):
	if Input.is_action_just_pressed("zoom_in"):
		var zoom_val = zoom.x - 0.1
		zoom = Vector2(zoom_val, zoom_val)
		
	if Input.is_action_just_pressed("zoom_out"):
		var zoom_val = zoom.x + 0.1
		zoom = Vector2(zoom_val, zoom_val)
	
	#if event is InputEventMouseButton:
		#pressed_mouse_pos = get_global_mouse_position()
		#print(pressed_mouse_pos)
		#if event.button_index == MOUSE_BUTTON_MIDDLE:
			#is_drag = event.is_pressed()
			#print(is_drag)
			#if is_drag: 
				#pos = position
			#
	#if event is InputEventMouseMotion:
		#if is_drag:
			#var mouse_offset = get_global_mouse_position() - pressed_mouse_pos
			#position = pos - mouse_offset
			
				
	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_MIDDLE:
			is_drag = event.is_pressed()
			if is_drag:
				pressed_mouse_pos = get_global_mouse_position()
				original_camera_pos = position  # 记录拖拽开始时摄像头的位置
			else:
				pressed_mouse_pos = Vector2.ZERO

	if event is InputEventMouseMotion:
		if is_drag:
			var mouse_offset = get_global_mouse_position() - pressed_mouse_pos
			position = original_camera_pos - mouse_offset  # 使用初始摄像头位置进行计算



	
	
